package com.tianqu.tms.www.transfer.action;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringUtils;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.tianqu.tms.core.base.TmsAction;
import com.tianqu.tms.core.base.UserContext;
import com.tianqu.tms.core.util.TmsConstants;
import com.tianqu.tms.entity.TransferAcceptedInfo;
import com.tianqu.tms.www.transfer.actionform.CheckConfirmActionForm;
import com.tianqu.tms.www.transfer.viewhelper.CheckConfirmViewHelper;

public class StatusRefundControlSearchResultAction extends TmsAction {

	@Override
	protected ActionForward doAction(ActionMapping mapping, ActionForm form, HttpServletRequest request,
			HttpServletResponse response, UserContext uc) throws Exception {
		CheckConfirmActionForm inputForm = (CheckConfirmActionForm) form;
		CheckConfirmViewHelper view = new CheckConfirmViewHelper();
		String serial = inputForm.getSerial();
		String status = inputForm.getStatus();
		
		view.setSerial(serial);
		view.setStatus(status);
		view.setIsShowTable("2");
//		view.setRemarks(inputForm.getRemarks());
		if(!StringUtils.isNotBlank(serial)) {
			String[] param = {"流水号"};
			setErrorsToRequest(request, TmsConstants.U0005, param);
			request.setAttribute(TmsConstants.VIEWHELP, view);
			return mapping.findForward(TmsConstants.SUCCESS);
		}
		
		List<TransferAcceptedInfo> list = TransferAcceptedInfo.getInstance().getAcceptInfoBySerialAndLicense(serial,"","");
		if(list == null) {
			setErrorsToRequest(request, TmsConstants.U0039, null);
			request.setAttribute(TmsConstants.VIEWHELP, view);
			return mapping.findForward(TmsConstants.SUCCESS);
		}
		TransferAcceptedInfo accept = list.get(0);
		if(list.size() > 1) {
			setErrorsToRequest(request, TmsConstants.U1405, null);
			request.setAttribute(TmsConstants.VIEWHELP, view);
			return mapping.findForward(TmsConstants.SUCCESS);
		}
		
		view.setCheckFileStatus(accept.getCheckFileStatus()+"");
		view.setChangeUsenature(accept.getChangeUsenature()+"");
		view.setSerial(accept.getSerial());
		view.setVin(accept.getVin());
		 
		request.setAttribute(TmsConstants.VIEWHELP,view);
		return mapping.findForward(TmsConstants.SUCCESS);
	}}
